package com.hzhjhh.view.manageView.menus.storage.addGoods;

import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.hzhjhh.init.dialog.Mytable;
import com.hzhjhh.view.manageView.menus.storage.AddGoodsDialog;
import com.hzhjhh.view.manageView.menus.storage.constant.ShowConstants;

/**
 * 菜单栏初始化-仓库-新增商品-添加按钮
 * 
 * @author 12083
 *
 */
public class AddBt {

	/**
	 * 按钮
	 */
	public static JButton btInit(AddGoodsDialog addGoodsDialog) {
		JButton add = new JButton();
		add.setBounds(53, 418, 127, 27);
        add.setText("添  加");
        add.addActionListener(event -> {
        	JTable jTable1 = addGoodsDialog.getJTable1();
        	Vector addAllData = addGoodsDialog.getAddAllData();
        	JScrollPane jScrollPane1 = addGoodsDialog.getJScrollPane1();
        	JTextField jTextField1 = addGoodsDialog.getTxfMerchandiseCode();
        	JTextField jTextField2 = addGoodsDialog.getTxfTreatyCode();
        	JTextField jTextField4 = addGoodsDialog.getTxfMerchandiseName();
        	JTextField jTextField5 = addGoodsDialog.getTxfRetailPrice();
        	JTextField jTextField6 = addGoodsDialog.getTxfSpec();
        	JTextField jTextField7 = addGoodsDialog.getTxfUnits();
        	JTextField jTextField8 = addGoodsDialog.getTxfPurchasePrice();
        	JTextField jTextField9 = addGoodsDialog.getTxfCheckTerm();
        	JTextField jTextField10 = addGoodsDialog.getTxfRemark();
        	JComboBox jComboBox1 = addGoodsDialog.getJComboBox1();
        	
        	if ((jTextField1.getText().length() == 0) || (jTextField2.getText().length() == 0)
    				|| (jTextField4.getText().length() == 0) || (jTextField5.getText().length() == 0)
    				|| (jTextField6.getText().length() == 0) || (jTextField7.getText().length() == 0)
    				|| (jTextField8.getText().length() == 0) || (jTextField9.getText().length() == 0)) {
    			JOptionPane.showMessageDialog(addGoodsDialog, "数据填写不完整，请重新填写", "提示", JOptionPane.ERROR_MESSAGE);
    			return;
    		}

    		try {
    			Double dj = new Double(jTextField5.getText());
    			Double jhj = new Double(jTextField5.getText());
    			Double bzq = new Double(jTextField5.getText());
    		} catch (Exception ex) {
    			JOptionPane.showMessageDialog(addGoodsDialog, "提交的数据不合法，请检查", "提示", JOptionPane.INFORMATION_MESSAGE);
    			return;
    		}

    		Vector addData = new Vector();
    		addData.add(jTextField1.getText());
    		addData.add(jTextField2.getText());
    		if (jComboBox1.getSelectedItem().equals("生鲜类")) {
    			addData.add("SX1001");
    		}
    		if (jComboBox1.getSelectedItem().equals("食品类")) {
    			addData.add("SP1002");
    		}
    		if (jComboBox1.getSelectedItem().equals("蔬果类")) {
    			addData.add("SG1003");
    		}
    		if (jComboBox1.getSelectedItem().equals("日用类")) {
    			addData.add("RY1005");
    		}
    		if (jComboBox1.getSelectedItem().equals("礼品类")) {
    			addData.add("LP1006");
    		}
    		if (jComboBox1.getSelectedItem().equals("电器类")) {
    			addData.add("DQ1004");
    		}
    		addData.add(jTextField4.getText());
    		addData.add(jTextField5.getText());
    		addData.add(jTextField6.getText());
    		addData.add(jTextField7.getText());
    		addData.add(jTextField8.getText());
    		addData.add(jTextField9.getText());
    		addData.add(jTextField10.getText());
    		addAllData.add(addData);
    		jTable1 = Mytable.maketable(addAllData, ShowConstants.ADD_GOODS_HEAD_NAME); // 显示内容
    		jScrollPane1.getViewport().add(jTable1);
        });
		return add;
	}
}
